package com.example.thread;

import org.slf4j.Logger;

public class ConfigThread {

    private final String serverKey;
    Logger logger = org.slf4j.LoggerFactory.getLogger(ConfigThread.class);
    private long watiTime;
    private Object object = new Object();
    private String appKey;
    private Object result;

    private volatile boolean isSucceed = false;

    public ConfigThread(long watiTime, String appKey, String serverKey, Object result) {
        this.watiTime = watiTime;
        this.appKey = appKey;
        this.serverKey = serverKey;
        this.result = result;
    }

    public Object getResponse() {
        synchronized (object) {
            if (!isSucceed) {
                try {
                    object.wait(watiTime);
                } catch (InterruptedException e) {
                }
            }
            return result;
        }
    }

    public void setResponse(Object result) {
        if (isSucceed) {
            return;
        }
        synchronized (object) {
            this.result = result;
            this.isSucceed = true;
            object.notify();
        }
    }

    public boolean isSucceed() {
        return isSucceed;
    }

    public void setSucceed(boolean succeed) {
        isSucceed = succeed;
    }

    public long getWatiTime() {
        return watiTime;
    }

    public void setWatiTime(long watiTime) {
        this.watiTime = watiTime;
    }

    public Object getObject() {
        return object;
    }

    public void setObject(Object object) {
        this.object = object;
    }

    public String getAppKey() {
        return appKey;
    }

    public void setAppKey(String appKey) {
        this.appKey = appKey;
    }

    public Object getResult() {
        return result;
    }

    public void setResult(Object result) {
        this.result = result;
    }

    public String getServerKey() {
        return serverKey;
    }
}
